<?php
// +----------------------------------------------------------------------
// |ZBPHP[基于ThinkPHP5.1开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2016-2019 http://www.benbenwangluo.com
// +----------------------------------------------------------------------
// | Author 似水星辰 [ 2630481389@qq.com ]
// +----------------------------------------------------------------------
// | 中犇软件 技术六部 出品
// +----------------------------------------------------------------------

namespace app\order\validate;

use think\Validate;

/**
 * 退换货原因验证器
 * @package app\goods\validate
 * @author 似水星辰 [2630481389@qq.com]
 */
class Refund extends Validate
{
    //定义规则
    protected $rule = [
        
        //"order_sn|订单号"=>["require"],         
        "refund_money|退款金额"=>["require","float","gt"=>0],
        
        "sku_id|规格ID"=>["require","integer","egt"=>0],
        "goods_id|商品ID"=>["require","integer","gt"=>0],
        "num|退货数量"=>["require","integer","gt"=>0],
        
        "refund_type|退款方式"=>["require","in"=>[1,2]],
        "refund_reason|退款原因"=>["require","max"=> 100],
        "refund_picture|图片或视频"=>["checkIds"=> 3],
        "refund_content|退款内容"=>["max"=> 200],
    ];

    protected $message = [
        
    ];

    // 定义验证场景
    protected $scene = [
        "money"=>["sku_id","goods_id","num"]
      
    ];
    
     /**
     * Ids验证器
     * @author 晓风<215628355@qq.com>
     * @param string $value 值
     * @param int $rule 规则
     * @param array $data 数据
     * @param string $filed 字段
     * @return boolean
     */
    protected function checkIds($value,$rule,$data=[],$filed = ""){
        $arr = explode(",",$value);
        if(count($arr) > $rule){
            return  ":attribute最多可选". $rule. "个";
        }
        foreach($arr as $v){
            if(!preg_match( '/^\d+$/',$v)){
                return ":attribute只能是数字列表组成";
            }
        } 
        return true;
    }
}
